import json
import 回溯算法alg

def run_tests():
    # 加载测试用例
    with open("test_cases.json") as f:
        test_cases = json.load(f)
    
    passed = 0
    failed = []
    
    # 执行所有测试用例
    for i, case in enumerate(test_cases):
        dataA = case["dataA"]
        dataB = case["dataB"]
        expected = case["expected"]
        
        # 执行算法
        result = 回溯算法alg.encryptionCalculate(dataA, dataB)
        
        # 验证结果
        if result == expected:
            passed += 1
            status = "PASSED"
        else:
            failed.append({
                "test_case": i + 1,
                "input": (dataA, dataB),
                "expected": expected,
                "actual": result
            })
            status = "FAILED"
        
        # 显示测试结果
        print(f"Test {i+1}: {status} | "
              f"Input: ({dataA}, {dataB}) | "
              f"Expected: {expected} | "
              f"Got: {result}")
    
    # 输出统计摘要
    print("\n=== TEST SUMMARY ===")
    print(f"Total: {len(test_cases)} | Passed: {passed} | Failed: {len(failed)}")
    
    # 显示失败详情
    if failed:
        print("\nFailed Cases:")
        for fail in failed:
            print(f"Test {fail['test_case']}:")
            print(f"  Input: ({fail['input'][0]}, {fail['input'][1]})")
            print(f"  Expected: {fail['expected']}, Got: {fail['actual']}")

if __name__ == "__main__":
    run_tests()